<template>
	<view class="pageview">
		<cl-navbar autoBack placeholder :title="$t('chat.group_chat_manage.title')"></cl-navbar>
		<view class="pageContent">
			<view class="cellviewGrop">
				<view class="cellview">
					<view class="cellview__left">
						<text class="cellview__left__title">{{$t("chat.group_chat_manage.allSilent")}}</text>
					</view>
					<view class="cellview__right">
						<u-switch v-model="groupInfo.is_muted" asyncChange  @change="e=>setChange('is_muted',e)" size="20"
							:activeValue="1" :inactiveValue="0" inactiveColor="#121325"
							activeColor="#121325"></u-switch>
					</view>
				</view>
				<!-- 消息审核 -->
				<view class="cellview">
					<view class="cellview__left">
						<text class="cellview__left__title">{{$t("chat.group_chat_config.is_review")}}</text>
					</view>
					<view class="cellview__right">
						<u-switch v-model="groupInfo.is_review" asyncChange  @change="e=>setChange('is_review',e)" size="20"
							:activeValue="1" :inactiveValue="0" inactiveColor="#121325"
							activeColor="#121325"></u-switch>
					</view>
				</view>
				
				<!-- 隐藏群成员 -->
				<view class="">
					<view class="cellview">
						<view class="cellview__left">
							<text class="cellview__left__title">{{$t("chat.group_chat_config.show_member_list")}}</text>
						</view>
						<view class="cellview__right">
							<u-switch v-model="groupInfo.show_member_list" asyncChange  @change="e=>setChange('show_member_list',e)" size="20"
								:activeValue="0" :inactiveValue="1" inactiveColor="#121325"
								activeColor="#121325"></u-switch>
						</view>
					</view>
					<view style="margin: 0 40rpx;font-size: 26rpx;color: #61626e;margin-top: -30rpx;">打开此选项可以隐藏此群组的成员列表，但可以看到群组管理员列表。</view>
				</view>
				
				<view class="cellview" @click="setBanned">
					<view class="cellview__left">
						<text class="cellview__left__title">{{$t("chat.group_chat_manage.oneSilent")}}</text>
					</view>
					<view class="cellview__right">
						<u-icon name="arrow-right" color="#ffffff"></u-icon>
					</view>
				</view>
				<view class="cellview" @click="configGo">
					<view class="cellview__left">
						<text class="cellview__left__title">{{$t("chat.group_chat_manage.authority")}}</text>
					</view>
					<view class="cellview__right">
						<u-icon name="arrow-right" color="#ffffff"></u-icon>
					</view>
				</view>
				
			</view>
			<view class="cellviewGrop" v-if="groupInfo.userRole == 'creator'">
				<view class="cellview" @click="setManage">
					<view class="cellview__left">
						<text class="cellview__left__title">{{$t("chat.group_chat_manage.setManage")}}</text>
					</view>
					<view class="cellview__right">
						<u-icon name="arrow-right" color="#ffffff"></u-icon>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import sqliteGroup from '@/sqlite_services/group.js'
	import sqliteSeesion from '@/sqlite_services/seesion.js'
	import upload from '@/common/upload/upload.js'
	import groupApi from '@/services/api/group.js'
	import {
		mapState
	} from 'vuex'
	export default {
		name: 'group_chat_manage',
		data() {
			return {
				editInfoData: {
					type: '',
					title: '',
					model: '',
					data: {}
				}
			}
		},
		async onLoad() {
			console.log(this.groupInfo);
		},
		computed: {
			...mapState({
				groupInfo: state => state.chat.chatGroupInfo,
			}),
		},
		methods: {
			setBanned(){
				this.$Router.push({
					name:'group_members',
					params: {
						type:'banned',
						group_id:this.groupInfo.group_id
					}
				})
			},
			setManage(){
				this.$Router.push({
					name:'group_set_manage',
					params: {
						group_id:this.groupInfo.group_id
					}
				})
			},
			
			configGo(){
				this.$Router.push({
					name: 'group_chat_config'
				})
			},
			async apiUpdate(data) {
				try{
					let resapi = await groupApi.editGroupConf(data)
					if (resapi) {
						uni.showToast({
							title: resapi.msg,
							icon: 'none'
						})
						return true
					}else{
						return false
					}
				}catch(e){
					throw e
				}
			},
			async setChange(type, val) {
				let {
					group_id,
					is_review,
					is_invitation,
					show_sys_msg,
					show_online_number,
					show_member_list,
					show_ip,
					show_history,
					show_qun_number,
					can_delete_quit_msg,
					can_withdraw_self_msg,
					can_withdraw_other_msg,
					can_send_card,
					can_quit_range,
					can_add_friends,
					can_edit_msg,
					is_muted
				} = this.groupInfo
				
				//这里需要更新用户表和会话表
				let data = {
					group_id,
					is_review,
					is_invitation,
					show_sys_msg,
					show_online_number,
					show_member_list,
					show_ip,
					show_history,
					show_qun_number,
					can_delete_quit_msg,
					can_withdraw_self_msg,
					can_withdraw_other_msg,
					can_send_card,
					can_quit_range,
					can_add_friends,
					can_edit_msg,
					is_muted
				}
				data[type] = val
				this.apiUpdate(data)
			}
		},
	};
</script>

<style scoped lang="scss">
	.topInfo {
		background: #1E1F30;
		border-radius: 20rpx;
		margin: 20rpx 30rpx 0;
		padding: 30rpx;

		&__numview {
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 28rpx;
			color: #FFFFFF;

			&__right {
				display: flex;
				align-items: center;

				&__num {
					font-size: 28rpx;
					color: #61626e;
				}
			}
		}

		&__view {
			display: flex;
			margin-top: 30rpx;
			gap: 10rpx;

			&__item {
				display: flex;
				flex-direction: column;
				align-items: center;
				width: 120rpx;

				&__nickname {
					font-size: 24rpx;
					color: #FFFFFF;
					margin-top: 20rpx;
				}
			}

		}
	}
	.cellviewGrop {
		background: #1E1F30;
		border-radius: 20rpx;
		margin: 20rpx 30rpx 0;
	
		.cellview {
			display: flex;
			justify-content: space-between;
			padding: 20rpx;
			min-height: 70rpx;
			&__left {
				display: flex;
				align-items: center;
				
				&__title {
					font-size: 28rpx;
					margin-left: 20rpx;
					color: #FFFFFF;
				}
			}
			&__right {
				display: flex;
				align-items: center;
			
				&__content {
					font-size: 28rpx;
					color: #61626e;
				}
			}
		}
	}
	
	.controlsBotton {
		height: 110rpx;
		text-align: center;
		line-height: 110rpx;
		background: #1E1F30;
		border-radius: 20rpx;
		margin: 20rpx 30rpx 50rpx;
		font-size: 32rpx;
		color: #FF5252;
	}
</style>